package logic

import (
	"context"
	"meituan-waimai/models/mysql"

	"meituan-waimai/meituanrpc/internal/svc"
	"meituan-waimai/meituanrpc/meituanrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShoppingCardDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShoppingCardDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShoppingCardDelLogic {
	return &ShoppingCardDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShoppingCardDelLogic) ShoppingCardDel(in *meituanrpc.ShoppingCardDelRequest) (*meituanrpc.ShoppingCardDelResponse, error) {
	// todo: add your logic here and delete this line
	// 删除购物车的商品
	var shoppingCard mysql.ShoppingCard
	mysql.DB.Where("user_id = ? AND goods_id = ?", in.UserId, in.GoodsId).First(&shoppingCard)
	mysql.DB.Delete(&shoppingCard)
	return &meituanrpc.ShoppingCardDelResponse{}, nil
}
